/*
* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty.  In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/

#ifndef B2_DISTANCE_H
#define B2_DISTANCE_H

#include "../Common/b2Math.h"
#include <limits.h>

/// Used to warm start b2Distance.
/// Set count to zero on first call.
struct b2SimplexCache
{
	float32 metric;		// length or area.
	uint32	count;		//
	uint8	indexA[3];	// vertices on ShapeA.
	uint8	indexB[3];	// vertices on ShapeB.
};

/// Input for b2Distance.
/// You have to option to use the shape radii in the computation.
struct b2DistanceInput
{
	b2XForm	transformA;
	b2XForm transformB;
	bool	useRadii;
};

/// Out put for b2Distance.
struct b2DistanceOutput
{
	b2Vec2	pointA;		// Closest point on shapeA.
	b2Vec2	pointB;		// Closest point on shapeB.
	float32 distance;
	int32	iterations;	// number of GJK iteration used.
};

/// Compute the closest point between two shapes,Support any combination of:b2CircleShape, b2EdgeShape, b2PolygonShape.
/// The simplex is input/output, On the first call, set the b2SimplexCache.count to zero.
template<typename TA, typename TB>
void b2Distance(b2DistanceOutput* output, b2SimplexCache* cache, const b2DistanceInput* input, const TA* shapeA, const TB* shapeB);

#endif
